package com.mingloucct.payment_ws.controller;


import com.mingloucct.payment_ws.entity.Mlusers;
import com.mingloucct.payment_ws.service.IMlusersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@CrossOrigin
@RestController
@RequestMapping(value = "/mlusers")
public class MlusersController {
    @Autowired
    private IMlusersService iMlusersService;
    @RequestMapping(value = "/loginMlusers", method = RequestMethod.POST)
    private Mlusers loginMlusers(@RequestParam String username, @RequestParam String password, @RequestParam String value){
        Mlusers mlusers = iMlusersService.loginMlusers(username, password,value);
        if(mlusers!=null){
            String token = UUID.randomUUID()+"";
            mlusers.token=token;
        }
        return mlusers;
    }
    @RequestMapping(value = "/selectMlusers", method = RequestMethod.GET)
    private Mlusers selectMlusers(@RequestParam String username){
        Mlusers mlusers = iMlusersService.selectMlusers(username);
        return mlusers;
    }
    @RequestMapping(value = "/editMlusers", method = RequestMethod.GET)
    private void editMlusers(@RequestParam String username,
                                @RequestParam String realname,
                                @RequestParam String mobile,
                                @RequestParam String notes,
                                @RequestParam String createtime){
        iMlusersService.editMlusers(username, realname,mobile,notes,createtime);
    }

    @RequestMapping(value = "/selectAll", method = RequestMethod.POST)
    private List<Mlusers> selectAll(@RequestParam String username){
        List<Mlusers> mlusers = iMlusersService.selectAll(username);
        return mlusers;
    }

    @RequestMapping(value = "/changePermission", method = RequestMethod.POST)
    private void changePermission(@RequestParam int userid,
                                  @RequestParam String upload,
                                  @RequestParam String getfile,
                                  @RequestParam String city,
                                  @RequestParam String android
    ){
        upload=upload.equals("true")?"1":"0";
        getfile=getfile.equals("true")?"1":"0";
        city=city.equals("true")?"1":"0";
        android=android.equals("true")?"1":"0";
       iMlusersService.changePermission(userid,upload,getfile,city,android);
    }


}
